<script language="javascript">
<?php
		$format =  TI18n::Locale()->DateFormat();
		$format = preg_replace('/d/','dd',$format);
		$format = preg_replace('/j/','d',$format);
		$format = preg_replace('/j/','d',$format);
		$format = preg_replace('/l/','DD',$format);
		$format = preg_replace('/F/','MM',$format);
		$format = preg_replace('/m/','mm',$format);
		$format = preg_replace('/n/','m',$format);
		$format = preg_replace('/n/','m',$format);
		$format = preg_replace('/Y/','yy',$format);
		$format = preg_replace('/y/','y',$format);

?>

function MadFileBrowser(field_name, url, type, win) {
	  tinyMCE.activeEditor.windowManager.open({
	      file : <?php echo json_encode($this->SERVICE->Url("mfm",null,null,array("field"=>"__field__","url"=>"__url__"))); ?>.replace("__field__",field_name).replace("__url__",url),
	      title : 'File Manager',
	      width : 640,
	      height : 450,
	      resizable : "no",
	      inline : "yes",
	      close_previous : "no"
	  }, {
	      window : win,
	      input : field_name
	  });
	  return false;
}

	$(document).ready(function(){  
		$("input.date-editor").datepicker({
			changeMonth:true,
			changeYear:true,
			constrainInput:true,
			dateFormat:"<?php echo $format; ?>",
			dayNames:<?php echo json_encode(TI18n::Locale()->WeekDayNames()); ?>,
			dayNamesMin:<?php echo json_encode(TI18n::Locale()->WeekDayNames(ILocale::NT_MIN)); ?>,
			dayNamesShort:<?php echo json_encode(TI18n::Locale()->WeekDayNames(ILocale::NT_SHORT)); ?>,
			firstDay:<?php echo TI18n::Locale()->FirstWeekDay(); ?>,
			monthNames:<?php echo json_encode(TI18n::Locale()->MonthNames(ILocale::NT_SHORT)); ?>,
			monthNamesShort:<?php echo json_encode(TI18n::Locale()->MonthNames(ILocale::NT_SHORT)); ?>,
			yearRange:"1950:2050"			
		});
 				
		$("textarea.wysiwyg").tinymce({
				script_url : "{% $THEME_URL %}/js/tiny_mce/tiny_mce.js",
				mode : "textareas",
		        theme : "advanced",
		        plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
		        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		        theme_advanced_toolbar_location : "top",
		        theme_advanced_toolbar_align : "left",
		        theme_advanced_statusbar_location : "bottom",
		 //       theme_advanced_resizing : true,
		        height: "390",
		        relative_urls : false,
		        file_browser_callback : "MadFileBrowser"
		});
	});
</script>
